package com.alks.function.mapper.chengKong;

import com.alks.entity.data.entity.PcCutLotPriceDetail;
import com.alks.entity.data.entity.PcCutLotPriceDetailO;
import com.alks.entity.data.entity.PcCutPriceDetail;
import com.alks.entity.data.entity.PcCutPriceDetailO;
import com.alks.function.data.dto.chengKong.cost.*;
import com.alks.function.data.dto.chengKong.export.PunchingExportVo;
import com.alks.function.data.dto.chengKong.produce.StyleDetailDto;
import com.alks.function.data.dto.finance.fincons.LotNoDto;
import com.alks.function.data.request.chengKong.StyleNoRequest;
import com.alks.function.data.request.chengKong.cost.LotNoCutPriceRequest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;


public interface CostAssignmentMapper {

    /**
     * 冲裁选择型体查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT s.STYLE as styleNo,s.STYLE_COLOR,s.COLOR_CODE FROM SD_STYLE_PROCESS_HEAD s",
            "<where>",
            "and CFM_FLAG='Y' and COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "and NOT EXISTS (SELECT 1 FROM PC_CUT_PRICE_DETAIL p WHERE s.STYLE = p.STYLE and s.STYLE_COLOR=p.STYLE_COLOR and s.COMPANY_ID=p.COMPANY_ID)",
            "</where>",
            "</script>",
    })
    List<StyleDetailDto> getSelectTypeList(StyleNoRequest request);

    /**
     * 手工选择型体查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT s.STYLE as styleNo,s.STYLE_COLOR,s.COLOR_CODE FROM SD_STYLE_PROCESS_HEAD s",
            "<where>",
            "and CFM_FLAG='Y' and COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "and NOT EXISTS (SELECT 1 FROM PC_CUT_PRICE_DETAIL_O p WHERE s.STYLE = p.STYLE and s.STYLE_COLOR=p.STYLE_COLOR and s.COMPANY_ID=p.COMPANY_ID)",
            "</where>",
            "</script>",
    })
    List<StyleDetailDto> getSelectTypeList2(StyleNoRequest request);

    /**
     * 冲裁型体资料查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT t1.STYLE as styleNo,t1.STYLE_COLOR,t.COLOR_CODE,t1.CFM_FLAG from SD_STYLE_COLOR_PHOTO t RIGHT JOIN " +
            "(select  STYLE,STYLE_COLOR,COLOR_CODE,CFM_FLAG,SYS_DATE from PC_CUT_PRICE_DETAIL GROUP BY STYLE,STYLE_COLOR,COLOR_CODE)t1 " +
            "on t.STYLE_NO=t1.STYLE and t.STYLE_COLOR=t1.STYLE_COLOR",
            "<where>",
            "and COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and t1.STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "</where>",
            "<if test='sortNo != null and sortNo==3'>",
            "order by t1.STYLE asc",
            "</if>",
            "<if test='sortNo != null and sortNo==4'>",
            "order by t1.STYLE desc",
            "</if>",
            "<if test='sortNo == null'>",
            "ORDER BY t1.SYS_DATE desc",
            "</if>",
            "</script>",
    })
    List<StyleDetailToFlagDto> getTypeInformationList(StyleNoRequest request);

    /**
     * 手工型体资料查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT t1.STYLE as styleNo,t1.STYLE_COLOR,t.COLOR_CODE,t1.CFM_FLAG from SD_STYLE_COLOR_PHOTO t RIGHT JOIN " +
            "(select  STYLE,STYLE_COLOR,CFM_FLAG,SYS_DATE from PC_CUT_PRICE_DETAIL_O GROUP BY STYLE,STYLE_COLOR,CFM_FLAG)t1  " +
            "on t.STYLE_NO=t1.STYLE and t.STYLE_COLOR=t1.STYLE_COLOR",
            "<where>",
            "and COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and t1.STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "</where>",
            "<if test='sortNo != null and sortNo==3'>",
            "order by t1.STYLE asc",
            "</if>",
            "<if test='sortNo != null and sortNo==4'>",
            "order by t1.STYLE desc",
            "</if>",
            "<if test='sortNo == null'>",
            "ORDER BY t1.SYS_DATE desc",
            "</if>",
            "</script>",
    })
    List<StyleDetailToFlagDto> getTypeInformationList2(StyleNoRequest request);

    /**
     * 冲裁型体单价明细
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @return
     */
    @Select("select COMPANY_ID,SEQ_NO,PART_NAME,MTL_NAME,PIECE_NUM,CUT_LAYER,CUT_PRICE,REMARK,NO_PRICE_FLAG from PC_CUT_PRICE_DETAIL where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId} order by SEQ_NO asc ")
    List<PcCutPriceDetailDto> getUnitPriceOfPunchingType(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 查询型体排除颜色
     * @param styleNo
     * @param styleColor
     * @return
     */
    @Select("select COMPANY_ID,STYLE,STYLE_COLOR,SEQ_NO,PART_NAME,MTL_NAME,PIECE_NUM,CUT_LAYER,CUT_PRICE,REMARK,NO_PRICE_FLAG from PC_CUT_PRICE_DETAIL where STYLE=#{styleNo} and STYLE_COLOR!=#{styleColor} " +
            "and COMPANY_ID=#{companyId} order by SEQ_NO asc ")
    List<PcCutPriceDetail> getUnitPriceOfPunchingType2(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 查询工艺冲裁数据
     * @param styleNo
     * @param styleColor
     * @param companyId
     */
    List<SdStyleProcessNewDto> getSdStyleProcessNewToBlankingList(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor,  @Param("companyId") String companyId);

    /**
     * 查询型体冲裁资料是否存在
     * @param styleNo
     * @param styleColor
     * @param companyId
     */
    @Select("select count(1) from PC_CUT_PRICE_DETAIL where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId}")
    Integer getPcCutPriceDetailExist(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 把数据写入到冲裁单价明细
     * @param list
     */
    @Insert({
            "<script>",
            "INSERT INTO PC_CUT_PRICE_DETAIL (COMPANY_ID, STYLE, SEQ_NO, PART_NAME, MTL_NAME, PIECE_NUM, CUT_LAYER, CUT_NUM, PER_CUT_PRICE, CUT_PRICE, CHECK_PERCENT, CHECK_PRICE, REMARK, SYS_DATE, SYS_USER, CUT_UNION, CFM_FLAG, CFM_DATE, CFM_USER, NO_PRICE_FLAG, COLOR_CODE, STYLE_COLOR)",
            "VALUES",
            "<foreach item='t' collection='list' separator=','>",
            "(",
            "#{t.companyId}, #{t.style}, #{t.seqNo}, #{t.partName}, #{t.mtlName}, #{t.pieceNum}, #{t.cutLayer}, #{t.cutNum}, #{t.perCutPrice}, #{t.cutPrice}, #{t.checkPercent}, #{t.checkPrice}, #{t.remark}, #{t.sysDate}, #{t.sysUser}, #{t.cutUnion}, #{t.cfmFlag}, #{t.cfmDate}, #{t.cfmUser}, #{t.noPriceFlag}, #{t.colorCode}, #{t.styleColor}",
            ")",
            "</foreach>",
            "</script>"
    })
    void addPcCutPriceDetail(@Param("list") List<PcCutPriceDetail> list);

    /**
     * 删除冲裁单价明细
     * @param styleNo
     * @param styleColor
     * @param companyId
     */
    @Delete("delete from PC_CUT_PRICE_DETAIL where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId}")
    void deletePcCutPriceDetail(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 删除手工单价明细
     * @param styleNo
     * @param styleColor
     * @param companyId
     */
    @Delete("delete from PC_CUT_PRICE_DETAIL_O where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId}")
    void deletePcCutPriceDetail0(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 冲裁型体单价明细修改
     * @param list
     */
    @Update({
            "<script>",
            "<foreach item='t' collection='list' separator=';'>",
            "UPDATE PC_CUT_PRICE_DETAIL set PIECE_NUM=#{t.pieceNum},CUT_LAYER=#{t.cutLayer},CUT_PRICE=#{t.cutPrice},REMARK=#{t.remark},NO_PRICE_FLAG=#{t.noPriceFlag},SYS_DATE=#{t.sysDate},SYS_USER=#{t.sysUser} where STYLE=#{t.style} and STYLE_COLOR=#{t.styleColor} and SEQ_NO=#{t.seqNo} " +
                    "and COMPANY_ID=#{t.companyId}",
            "</foreach>",
            "</script>",
    })
    void updatePcCutPriceDetail(@Param("list") List<PcCutPriceDetail> list);

    /**
     * 0检核/1取消检核
     *
     * @param styleNo
     * @param styleColor
     * @param flag
     * @param dateTime
     * @param userName
     * @param companyId
     */
    @Update("update PC_CUT_PRICE_DETAIL set CFM_FLAG=#{flag},CFM_DATE=#{dateTime},CFM_USER=#{userName} where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId}")
    void updatePcCutPriceDetailToCheck(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor,
                                       @Param("flag") String flag, @Param("dateTime") LocalDateTime dateTime,
                                       @Param("userName") String userName, @Param("companyId") String companyId);

    /**
     * 冲裁指令选择指令
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT t.LOT_NO,t.STYLE,t.COLOR,t.COLOR_CODE,t1.CFM_FLAG FROM (SELECT LOT_NO, STYLE, COLOR, COLOR_CODE,COMPANY_ID FROM PC_LOT_HEAD AS S WHERE CHECK_FLAG = 'Y' AND CFM_FLAG= 'Y'AND NOT EXISTS " +
                    "(SELECT 1 FROM PC_CUT_LOT_PRICE_DETAIL AS P WHERE P.STYLE = S.STYLE AND P.LOT_NO = S.LOT_NO AND P.STYLE_COLOR = S.COLOR))t LEFT JOIN" +
                    "(select STYLE,STYLE_COLOR,COLOR_CODE,CFM_FLAG from PC_CUT_PRICE_DETAIL where CFM_FLAG='Y' GROUP BY STYLE,STYLE_COLOR,COLOR_CODE)t1 on t.STYLE=t1.STYLE and t.COLOR=t1.STYLE_COLOR",
            "<where>",
            "t.COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and t.STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "<if test='lotNo != null and !lotNo.isEmpty()'>",
            "and t.LOT_NO LIKE concat('%',#{lotNo},'%')",
            "</if>",
            "</where>",
            "<if test='sortNo != null and sortNo==1'>",
            "order by t.LOT_NO asc",
            "</if>",
            "<if test='sortNo != null and sortNo==2'>",
            "order by t.LOT_NO desc",
            "</if>",
            "<if test='sortNo != null and sortNo==3'>",
            "order by t.STYLE asc",
            "</if>",
            "<if test='sortNo != null and sortNo==4'>",
            "order by t.STYLE desc",
            "</if>",
            "</script>",
    })
    List<LotNoDetailDto> getLotNoDetail(LotNoCutPriceRequest request);

    /**
     * 手工指令选择型体
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "SELECT t.LOT_NO,t.STYLE,t.COLOR,t.COLOR_CODE,t1.CFM_FLAG FROM (SELECT LOT_NO, STYLE, COLOR, COLOR_CODE,COMPANY_ID FROM PC_LOT_HEAD AS S WHERE CHECK_FLAG = 'Y' AND CFM_FLAG= 'Y'AND NOT EXISTS " +
                    "(SELECT 1 FROM PC_CUT_LOT_PRICE_DETAIL_O AS P WHERE P.STYLE = S.STYLE AND P.LOT_NO = S.LOT_NO AND P.STYLE_COLOR = S.COLOR))t LEFT JOIN" +
                    "(select STYLE,STYLE_COLOR,CFM_FLAG from PC_CUT_PRICE_DETAIL_O where CFM_FLAG='Y' GROUP BY STYLE,STYLE_COLOR)t1 on t.STYLE=t1.STYLE and t.COLOR=t1.STYLE_COLOR",
            "<where>",
            "t.COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and t.STYLE LIKE concat('%',#{styleNo},'%')",
            "</if>",
            "<if test='lotNo != null and !lotNo.isEmpty()'>",
            "and t.LOT_NO LIKE concat('%',#{lotNo},'%')",
            "</if>",
            "</where>",
            "<if test='sortNo != null and sortNo==1'>",
            "order by t.LOT_NO asc",
            "</if>",
            "<if test='sortNo != null and sortNo==2'>",
            "order by t.LOT_NO desc",
            "</if>",
            "<if test='sortNo != null and sortNo==3'>",
            "order by t.STYLE asc",
            "</if>",
            "<if test='sortNo != null and sortNo==4'>",
            "order by t.STYLE desc",
            "</if>",
            "</script>",
    })
    List<LotNoDetailDto> getLotNoDetail2(LotNoCutPriceRequest request);

    /**
     * 冲裁指令查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "select LOT_NO, STYLE, STYLE_COLOR as color, CFM_FLAG, MIN(SYS_DATE),COMPANY_ID from PC_CUT_LOT_PRICE_DETAIL",
            "<where>",
            "COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and STYLE LIKE concat('%', #{styleNo}, '%')",
            "</if>",
            "<if test='lotNo != null and !lotNo.isEmpty()'>",
            "and LOT_NO LIKE concat('%', #{lotNo}, '%')",
            "</if>",
            "<if test='inTime != null and outTime != null'>",
            "and SYS_DATE BETWEEN #{inTime} AND #{outTime}",
            "</if>",
            "<if test='inTime != null and outTime == null'>",
            "and SYS_DATE &gt;= #{inTime}",
            "</if>",
            "<if test='outTime != null and inTime == null'>",
            "and SYS_DATE &lt;= #{outTime}",
            "</if>",
            "</where>",
            "group by LOT_NO, STYLE, STYLE_COLOR",
            "<if test='sortNo != null and sortNo==1'>",
            "order by LOT_NO asc",
            "</if>",
            "<if test='sortNo != null and sortNo==2'>",
            "order by LOT_NO desc",
            "</if>",
            "</script>",
    })
    List<LotNoDetailDto> getLotNoDetailList(LotNoCutPriceRequest request);

    /**
     * 手工指令查询
     * @param request
     * @return
     */
    @Select({
            "<script>",
            "select LOT_NO, STYLE, STYLE_COLOR as color, CFM_FLAG, MIN(SYS_DATE) ,COMPANY_ID from PC_CUT_LOT_PRICE_DETAIL_O",
            "<where>",
            "COMPANY_ID=#{companyId}",
            "<if test='styleNo != null and !styleNo.isEmpty()'>",
            "and STYLE LIKE concat('%', #{styleNo}, '%')",
            "</if>",
            "<if test='lotNo != null and !lotNo.isEmpty()'>",
            "and LOT_NO LIKE concat('%', #{lotNo}, '%')",
            "</if>",
            "<if test='inTime != null and outTime != null'>",
            "and SYS_DATE BETWEEN #{inTime} AND #{outTime}",
            "</if>",
            "<if test='inTime != null and outTime == null'>",
            "and SYS_DATE &gt;= #{inTime}",
            "</if>",
            "<if test='outTime != null and inTime == null'>",
            "and SYS_DATE &lt;= #{outTime}",
            "</if>",
            "</where>",
            "group by LOT_NO, STYLE, STYLE_COLOR",
            "<if test='sortNo != null and sortNo==1'>",
            "order by LOT_NO asc",
            "</if>",
            "<if test='sortNo != null and sortNo==2'>",
            "order by LOT_NO desc",
            "</if>",
            "</script>",
    })
    List<LotNoDetailDto> getLotNoDetailList2(LotNoCutPriceRequest request);

    /**
     * 指令冲裁单价明细
     *
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("select SEQ_NO,PART_NAME,MTL_NAME,PIECE_NUM,CUT_LAYER,CUT_PRICE,REMARK from PC_CUT_LOT_PRICE_DETAIL where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId} order by SEQ_NO asc ")
    List<PcCutPriceDetailDto> getPcCutLotPriceDetail(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 生成冲裁指令单价明细
     * @param list
     */
    @Insert({
            "<script>",
            "INSERT INTO PC_CUT_LOT_PRICE_DETAIL (COMPANY_ID, STYLE, LOT_NO, SEQ_NO, PART_NAME, MTL_NAME, PIECE_NUM, ",
            "CUT_LAYER, CUT_NUM, PER_CUT_PRICE, CUT_PRICE, CHECK_PERCENT, CHECK_PRICE, REMARK, SYS_DATE, ",
            "SYS_USER, CUT_UNION, STYLE_COLOR, CFM_FLAG, CFM_DATE, CFM_USER) ",
            "VALUES ",
            "<foreach collection='list' item='t' separator=','>",
            "(#{t.companyId}, #{t.style}, #{t.lotNo}, #{t.seqNo}, #{t.partName}, #{t.mtlName}, #{t.pieceNum}, ",
            "#{t.cutLayer}, #{t.cutNum}, #{t.perCutPrice}, #{t.cutPrice}, #{t.checkPercent}, #{t.checkPrice}, ",
            "#{t.remark}, #{t.sysDate}, #{t.sysUser}, #{t.cutUnion}, #{t.styleColor}, #{t.cfmFlag}, #{t.cfmDate}, #{t.cfmUser})",
            "</foreach>",
            "</script>"
    })
    void addPcCutLotPriceDetail(List<PcCutLotPriceDetail> list);

    /**
     * 删除冲裁指令单价明细
     *
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_CUT_LOT_PRICE_DETAIL where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void deletePcCutLotPriceDetail(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 工艺工序查询
     *
     * @param styleNo
     * @param styleColor
     * @param companyId
     */
    @Select(" select COMPANY_ID,SEQ_NO,PROCESS_TYPE,PROCESS,PART_NAME,PIECE_NUM,PRICE,REMARK from PC_CUT_PRICE_DETAIL_O where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId} order by SEQ_NO")
    List<PcCutPriceDetailODto> getPcCutPriceDetailO(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 查询型体排除颜色
     *
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @return
     */
    @Select(" select COMPANY_ID,STYLE,STYLE_COLOR,SEQ_NO,PROCESS_TYPE,PROCESS,PART_NAME,PIECE_NUM,PRICE,REMARK from PC_CUT_PRICE_DETAIL_O where STYLE=#{styleNo} and STYLE_COLOR!=#{styleColor} and COMPANY_ID=#{companyId} order by SEQ_NO")
    List<PcCutLotPriceDetailO> getPcCutPriceDetailO2(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 手工单价检核
     * @param styleNo
     * @param styleColor
     * @param flag
     * @param dateTime
     * @param userName
     */
    @Update("update PC_CUT_PRICE_DETAIL_O set CFM_FLAG=#{flag},CFM_DATE=#{dateTime},CFM_USER=#{userName} where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor}")
    void updatePcCutPriceDetail0ToCheck(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor,
                                        @Param("flag") String flag,@Param("dateTime") LocalDateTime dateTime,@Param("userName") String userName);

    /**
     * 查询导出手工单价基础信息
     *
     * @param styleNo
     * @param companyId
     */
    @Select("SELECT t1.ABBR_NAME as companyId,t.CUST_NO as custom,t.STYLE_NO as style from SD_STYLE t left join SD_COMPANY t1 on t.COMPANY_ID=t1.COMPANY_ID where t.STYLE_NO=#{styleNo} and t.COMPANY_ID=#{companyId}")
    PunchingExportVo getStyleDetail(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 删除手工指令单价信息
     *
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_CUT_LOT_PRICE_DETAIL_O where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void deletePcCutLotPriceDetail0(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 添加手工指令单价信息
     * @param list
     */
    @Insert({
            "<script>",
            "INSERT INTO PC_CUT_LOT_PRICE_DETAIL_O  (COMPANY_ID, STYLE, LOT_NO, PROCESS_CODE, SEQ_NO, PROCESS, PART_NAME, PIECE_NUM, CUT_NUM, PROCESS_TYPE, PER_PRICE, PRICE, REMARK, SYS_DATE, SYS_USER, STYLE_COLOR, CFM_FLAG, CFM_DATE, CFM_USER) ",
            "VALUES ",
            "<foreach collection='list' item='t' separator=','>",
            "(#{t.companyId}, #{t.style}, #{t.lotNo}, #{t.processCode}, #{t.seqNo}, #{t.process}, #{t.partName}, #{t.pieceNum}, #{t.cutNum}, #{t.processType}, #{t.perPrice}, #{t.price}, #{t.remark}, #{t.sysDate}, #{t.sysUser}, #{t.styleColor}, #{t.cfmFlag}, #{t.cfmDate}, #{t.cfmUser})",
            "</foreach>",
            "</script>"
    })
    void addPcCutLotPriceDetailO(@Param("list") List<PcCutLotPriceDetailO> list);

    /**
     * 手工单价明细
     *
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("select SEQ_NO,PROCESS,PROCESS_TYPE,PART_NAME,PIECE_NUM,PRICE,REMARK from PC_CUT_LOT_PRICE_DETAIL_O where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId} order by SEQ_NO asc ")
    List<PcCutPriceDetailODto> getPcCutLotPriceDetailO(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     *工艺工序修改
     * @param list
     */
    @Update({
            "<script>",
            "<foreach item='t' collection='list' separator=';'>",
            "UPDATE PC_CUT_PRICE_DETAIL_O set PIECE_NUM=#{t.pieceNum},PRICE=#{t.price},REMARK=#{t.remark},SYS_DATE=#{t.sysDate},SYS_USER=#{t.sysUser} where STYLE=#{t.style} and STYLE_COLOR=#{t.styleColor} and SEQ_NO=#{t.seqNo} and COMPANY_ID=#{t.companyId}",
            "</foreach>",
            "</script>",
    })
    void updatePcCutPriceDetail0(List<PcCutLotPriceDetailO> list);

    /**
     * 查询手工单价型体颜色是否建档
     *
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @return
     */
    @Select("select count(1) from PC_CUT_PRICE_DETAIL_O where STYLE=#{styleNo} and STYLE_COLOR=#{styleColor} and COMPANY_ID=#{companyId}")
    Integer getPcCutPriceDetail0Exist(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor, @Param("companyId") String companyId);

    /**
     * 获取冲裁工序
     * @return
     */
    @Select("select PROCESS from PC_CUTTING_PROCESS_DETAIL where PROCESS_CODE='01'")
    List<String> getProcessList();

    /**
     * 添加手工工艺工序
     * @param list
     */
    @Insert({
            "<script>",
            "INSERT INTO PC_CUT_PRICE_DETAIL_O (COMPANY_ID, STYLE, PROCESS_CODE, SEQ_NO, PROCESS, PART_NAME, PIECE_NUM, CUT_NUM, PROCESS_TYPE, PER_PRICE, PRICE, REMARK, SYS_DATE, SYS_USER, CFM_FLAG, CFM_DATE, CFM_USER, STYLE_COLOR) VALUES",
            "<foreach collection='list' item='t' index='index' separator=','>",
            "(#{t.companyId}, #{t.style}, #{t.processCode}, #{t.seqNo}, #{t.process}, #{t.partName}, #{t.pieceNum}, #{t.cutNum}, #{t.processType}, #{t.perPrice}, #{t.price}, #{t.remark}, #{t.sysDate}, #{t.sysUser}, #{t.cfmFlag}, #{t.cfmDate}, #{t.cfmUser}, #{t.styleColor})",
            "</foreach>",
            "</script>"
    })
    void addPcCutPriceDetailO(List<PcCutPriceDetailO> list);

    /*指令查询冲裁*/
    LotNoDto queryPcCutLotPriceDetail(@Param("companyId") String companyId, @Param("request") LotNoDto request);

    /*指令查询手工*/
    LotNoDto queryPcCutLotPriceDetailO(@Param("companyId") String companyId, @Param("request") LotNoDto request);

    /*指令冲裁检核1、取消检核2*/
    int updatePcCutLotPriceDetail(@Param("companyId") String companyId, @Param("request") LotNoDto request);

    /*指令手工检核1、取消检核2*/
    int updatePcCutLotPriceDetailO(@Param("companyId") String companyId, @Param("request") LotNoDto request);

    /**
     * 获取手工工序
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @return
     */
    List<SdStyleProcessNewDto> TakeDevelopmentDifferences2(@Param("styleNo") String styleNo,
                                                          @Param("styleColor") String styleColor,
                                                          @Param("companyId") String companyId);

    /**
     * 删除冲裁工序
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @param seqNo
     * @return
     */
    int delBySeqNo(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor,
                   @Param("companyId") String companyId, @Param("seqNo") String seqNo);

    /**
     * 删除手工工序
     * @param styleNo
     * @param styleColor
     * @param companyId
     * @param seqNo
     */
    int delBySeqNo2(@Param("styleNo") String styleNo, @Param("styleColor") String styleColor,
                     @Param("companyId") String companyId, @Param("seqNo") String seqNo);
}
